<template>
	<view class="uni-popup-param">
		<view class="uni-share-title"><text class="uni-share-title-text">{{paramTitleText}}</text></view>
		<view class="uni-list">
			<uni-list-item>
				<template v-slot:header><text class="slot-text">打印份数</text></template>
				<template v-slot:footer>
					<uni-number-box v-model="copyCount" :min="1" :max="10"></uni-number-box>
				</template>
			</uni-list-item>
			<uni-list-item>
				<template v-slot:header><text class="slot-text">纸张大小</text></template>
				<template v-slot:footer>
					<radio-group @change="radioPageSize">
						<label>
							<radio value="A4" checked />
							<text>A4</text>
						</label>
						<label>
							<radio value="A3" />
							<text>A3</text>
						</label>
					</radio-group>
				</template>
			</uni-list-item>
			<uni-list-item>
				<template v-slot:header><text class="slot-text">双面打印</text></template>
				<template v-slot:footer>
					<switch @change="duplexSwitch" />
				</template>
			</uni-list-item>
			<uni-list-item>
				<template v-slot:header><text class="slot-text">彩色打印</text></template>
				<template v-slot:footer>
					<switch @change="colorSwitch" />
				</template>
			</uni-list-item>
			<!-- <uni-list-item>
				<template v-slot:body>
					<button size="mini" @click="close">取消</button>
					<button size="mini" type="primary" @click="submit">确定</button>
				</template>
			</uni-list-item> -->
		</view>
		<view class="uni-share-button-box">
			<button type="default" class="uni-share-button" @click="close">取消</button>
			<text class="slot-text-s"></text>
			<button type="primary" class="uni-share-button-s" @click="submit">确定</button>
		</view>
	</view>
</template>

<script>
	import popup from '../uni-popup/popup.js'
	import {
		initVueI18n
	} from '@dcloudio/uni-i18n'
	import messages from '../uni-popup/i18n/index.js'
	const {
		t
	} = initVueI18n(messages)
	export default {
		name: 'UniPopupParam',
		mixins: [popup],
		emits: ['select'],
		props: {
			title: {
				type: String,
				default: ''
			},
			beforeClose: {
				type: Boolean,
				default: false
			},
			docTitle: {
				type: String,
				default: '选择打印属性'
			}
		},
		data() {
			return {
				copyCount: 1,
				pageSize: 'A4',
				deplex: 'OneSided',
				color: 'Grayscale',
			}
		},
		created() {
			console.info(this.docTitle);
		},
		computed: {
			paramTitleText() {
				return this.docTitle
			}
		},
		methods: {
			/**
			 * 关闭窗口
			 */
			close() {
				if (this.beforeClose) return
				this.popup.close()
			},
			radioPageSize(e) {
				this.pageSize = e.detail.value;
			},
			duplexSwitch(e) {
				if (e.detail.value) {
					this.deplex = 'TwoSided'
				}
			},
			colorSwitch(e) {
				if (e.detail.value) {
					this.color = 'Color';
				}
			},
			submit() {
				const param = {
					copyCount: this.copyCount,
					pageSize: this.pageSize,
					deplex: this.deplex,
					color: this.color
				};
				//console.log("打印属性:", param);
				//if (this.beforeClose) return
				uni.$emit('param', param);
				this.popup.close()
			}
		},
	}
</script>

<style lang="scss">
	.divider {
		background: #E0E3DA;
		width: 100%;
		height: 5rpx;
	}

	.slot-text {
		margin-top: 5px;
		/* flex: 1;
		font-size: 14px;
		color: #4cd964;
		margin-right: 10px; */
	}

	.slot-text-s {
		padding: 10px;
	}

	.uni-popup-share {
		background-color: #fff;
		border-top-left-radius: 11px;
		border-top-right-radius: 11px;
	}

	.uni-share-title {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
		justify-content: center;
		height: 40px;
	}

	.uni-share-title-text {
		font-size: 14px;
		color: #666;
	}

	.uni-share-content {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: center;
		padding-top: 10px;
	}

	.uni-share-content-box {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		flex-wrap: wrap;
		width: 360px;
	}

	.uni-share-content-item {
		width: 90px;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		padding: 10px 0;
		align-items: center;
	}

	.uni-share-content-item:active {
		background-color: #f5f5f5;
	}

	.uni-share-image {
		width: 30px;
		height: 30px;
	}

	.uni-share-text {
		margin-top: 10px;
		font-size: 14px;
		color: #3B4144;
	}

	.uni-share-button-box {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		padding: 0px 10px 25px 10px;
	}

	.uni-share-button {
		flex: 1;
		border-radius: 50px;
		//color: #666;
		font-size: 16px;
		padding-right: 0px;
	}

	.uni-share-button-s {
		flex: 1;
		border-radius: 50px;
		//color: #ffffff;
		font-size: 16px;
		padding-left: 0px;
	}

	.uni-share-button::after {
		border-radius: 50px;
	}
</style>
